package decision_tree.dto;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

import decision_tree.UnigramModel;
import decision_tree.question.Question;

public class TreeNode {
	public Map<Integer, TreeNode> children = new HashMap<Integer, TreeNode>();
	public Question q;
	public UnigramModel model;
	
//	public String toString() {
//		String str = q + "\r\n";
//		for(Entry<Integer, TreeNode> entry : children.entrySet()) {
//			str += entry.getValue().toString();
//		}
//		return str;
//	}
	
	public String toString(int layer) {
		if(q == null) {
			return "";
		}
		
		String str = getSpace(layer) + layer + "\t" + q + "\r\n";
		for(Entry<Integer, TreeNode> entry : children.entrySet()) {
			str += entry.getValue().toString(layer + 1);
		}
		return str;
	}
	
	protected String getSpace(int layer) {
		String s = "";
		for(int i = 0; i < layer; i++) {
			s += " ";
		}
		return s;
	}
}
